package org.jground.zk.zulX;

import org.jground.util.StringUtils;
import org.zkoss.zk.ui.Component;
import org.zkoss.zul.Html;
import org.zkoss.zul.Popup;
import org.zkoss.zul.Tab;
import org.zkoss.zul.Tabbox;
import org.zkoss.zul.Tabpanel;
import org.zkoss.zul.Tabpanels;
import org.zkoss.zul.Tabs;

public class TabboxX extends Tabbox {
    private Tabs tabs;
    private Tabpanels tabpanels;

    public TabboxX() {
        tabs = new Tabs();
        tabs.setParent(this);
        tabpanels = new Tabpanels();
        tabpanels.setParent(this);
    }

    public void addTab(String tabText, Component tabContent) {
        addTab(null, tabText, null, tabContent);
    }

    public void addTab(Component popupParent, String tabText, String description, Component tabContent) {
        Tab tab = new Tab(tabText);
        tab.setParent(tabs);
        if (StringUtils.isNotBlank(description)) {
            // attributeLb.setTooltiptext(description);
            Popup popup = new Popup();
            popup.setParent(popupParent);
            Html html = new Html(description);
            html.setParent(popup);
            tab.setTooltip(popup);
        }
        Tabpanel tabpanel = new Tabpanel();
        tabpanel.setParent(tabpanels);
        tabContent.setParent(tabpanel);
    }

    public void addSingleTab(Component tabContent) {
        tabs.setParent(null);
        Tabpanel tabpanel = new Tabpanel();
        tabpanel.setParent(tabpanels);
        tabContent.setParent(tabpanel);
    }

}
